$('#loginBtn').on('click',function(){
    axios.post('/api/stu/login',{username:$('#loginUser')[0].value,password: $('#loginPasswd')[0].value})
    .then(function(res){
        if(res.data.error){
            alert(res.data.error)
        }else if(res.data.warning){
            $('#pwdStuid').val($('#loginUser')[0].value)
            $('#pwdModal').modal('show')
        }else{
            if(localStorage.getItem('stu_token')){
                localStorage.removeItem('stu_token')
            }
            localStorage.setItem('stu_token',res.data.token)
            s = btoa(encodeURIComponent(JSON.stringify(res.data.data)))
            location.href = '/student?s='+s
        }    
    })
    return false;
})

$('#saveEditPwd').on('click',function(){
    user = $('#pwdStuid')[0].value
    pwd = $('#editPwd')[0].value
    newpwd = $('#newPwd')[0].value
    newpwd2 = $('#newPwd2')[0].value
    if(pwd == '' || newpwd == '' || newpwd2 == ''){
        alert('密码不能为空！！')
        return
    }
    if(newpwd !== newpwd2){
        alert('两次新密码不一致！！')
        return
    }
    axios.post('/api/stu/pwd',{username:user,password:pwd,newpassword:newpwd})
    .then(function(res){
        if(res.data.error){
            alert(res.data.error)
        }else{
            conf = confirm('修改成功,是否登录？？')
            if(!conf)return
            if(localStorage.getItem('stu_token')){
                localStorage.removeItem('stu_token')
            }
            localStorage.setItem('stu_token',res.data.token)
            s = btoa(encodeURIComponent(JSON.stringify(res.data.data)))
            location.href = '/student?s='+s
        }
    })
})